package com.queming.music.mapper;

import com.queming.core.mapper.FileMapper;
import com.queming.core.mapper.MapperInterface;
import com.queming.music.dto.ArtistDto;
import com.queming.music.dto.MusicCreateRequest;
import com.queming.music.dto.MusicDto;
import com.queming.music.dto.MusicUpdateRequest;
import com.queming.music.entity.Music;
import com.queming.music.vo.MusicVo;
import org.mapstruct.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chencidiao
 * @date 2022/05/03 15:41
 **/

@Mapper(componentModel = "spring",uses = {FileMapper.class},
        nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
        nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)

public interface MusicMapper extends MapperInterface<Music,MusicDto> {

    @Mapping(source = "fileId",target = "file.id")
    @Mapping(target = "artistList",source = "artistIds")
    MusicDto  toDto(MusicCreateRequest musicCreateRequest);

    @Mapping(source = "fileId",target = "file.id")
    @Mapping(target = "artistList",source = "artistIds")
    MusicDto toDto( MusicUpdateRequest musicUpdateRequest);

    MusicVo toVo(MusicDto musicDto);

    default List<ArtistDto> mapArtistList(List<String> artistIds){
        List<ArtistDto> artistList = new ArrayList<>();
       for(String id:artistIds){
           ArtistDto artistDto=new ArtistDto();
           artistDto.setId(id);
           artistList.add(artistDto);
       }
       return artistList;
    }
}
